<?php
/**
 * 家具详情页
 * User: tengyu
 * Date: 2017/8/29
 * Time: 20:11
 */?>
@extends('common.common')
@section('title','家具详情')
@section('css')
    <link rel="stylesheet" href="{{asset('/css/product_details.css')}}">
    <link rel="stylesheet" href="{{asset('/css/date.css')}}">
    <link rel="stylesheet" href="{{asset('/css/dateDefault.css')}}">
@endsection
@section('js')
    <script type="text/javascript" src="{{asset('/js/product.details.js')}}"></script>
    <script type="text/javascript" src="{{asset('/js/laydate.dev.js')}}"></script>
    <script type="text/javascript">
        laydate({
            elem: '#date'
        });
    </script>
    <script>
        /**组合加入购物车*/
        function add_combinecar(jsondata)
        {
            $.ajax({
                url:'/add_combine',
                type:'get',
                dataType:'json',
                data:{'jsondata':jsondata},
                success:function(res)
                {
                    if(res.res=='ok'){
                        alert(res.msg);
                        history.go(0);
                    }else{
                        alert(res.msg);
                    }
                }

            });
        }
        /***/
        function fitment_dt_rent(id)
        {
            $("input[name='rent_type']").attr("value",id);
        }
        /**加入购物车*/
        function cartinsert()
        {
            var num = $("#boom").text();
            var details_id = $("input[name='details_id']").val();
            var use_date = $("input[name='use_date']").val();
            var rent_type = $("input[name='rent_type']").val();
            if(!use_date){
                alert('请选择租赁日期!');return false;
            }
            $.ajax({
                url:'/shopcart/add',
                type:'post',
                dataType:'json',
                data:{'_token':"{{csrf_token()}}",'num':num,'details_id':details_id,'use_date':use_date,'rent_type':rent_type},
                success:function(res) {
                    if(res.res=='ok'){
                        alert(res.msg);
                        history.go(0);
                    }else{
                        alert(res.msg);
                    }
                }
            });
        }
        /**立即租赁*/
        function immediatorder()
        {
            var num = $("#boom").text();
            var details_id = $("input[name='details_id']").val();
            var use_date = $("input[name='use_date']").val();
            var rent_type = $("input[name='rent_type']").val();
            if(!use_date){
                alert('请选择租赁日期!');return false;
            }
            $.ajax({
                url:'/shopcart/add',
                type:'post',
                dataType:'json',
                data:{'_token':"{{csrf_token()}}",'num':num,'details_id':details_id,'use_date':use_date,'rent_type':rent_type},
                success:function(res) {
                    if(res.res=='ok'){
                        window.location.href = res.redirect;
                    }else{
                        alert(res.msg);
                    }
                }
            });
        }
    </script>
@endsection
@section('content')
    <div id="content">
        <div class="row">
        @include('common.centernav')
            <!--左边-->
            <div class="container">
                <div id="middle">
                    <div id="top">
                        <div class="left">
                            <div class="col-xs-13 col-xs-7">
                                <div class="A">
                                    <ul>
                                        <li>
                                            <img class="my-small" src="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgTwo)}}" data-target="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgTwo)}}" style="width: 90px;height: 90px;">
                                        </li>
                                        <li>
                                            <img class="my-small" src="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgThree)}}" data-target="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgThree)}}" style="width: 90px;height: 90px;">
                                        </li>
                                        <li>
                                            <img class="my-small" src="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgFour)}}" data-target="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgFour)}}" style="width: 90px;height: 90px;">
                                        </li>
                                        <li>
                                            <img class="my-small" src="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgFive)}}" data-target="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgFive)}}" style="width: 90px;height: 90px;">
                                        </li>
                                    </ul>
                                    <div class="img1">
                                        <img src="{{asset(env('STATIC_FILE_ERP_PATH').$param['current']->fitment_details_imgTwo)}}" class="my-big" style="width: 400px;height: 400px;">
                                        <div class="caption">
                                            <p>信用额度:当前信用额度 : ¥{{$param['current']->details_bond}} , 信用额度应付 : ¥{{$param['current']->details_bond}} , 您可用信用额度为¥@if(!empty($param['user_quota'])){{$param['user_quota']->quota_current}}@else{{'0'}}<a style="color: #b34848" href="{{url('/user/quota_apply')}}">开通信用额度</a>@endif</p>
                                        </div>
                                    </div>
                                </div>
                                <!--推荐组合-->
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h5>最佳搭配</h5>
                                    </div>
                                    <div class="panel-body">
                                        @if(count($param['combinedata'])>0 && count($param['combine'])>0)
                                            <?php $combine_sum = null;$combine_ids = array();?>
                                            @foreach($param['combine'] as $key=>$value)
                                            <div class="img2">
                                                <dl>
                                                    <dt><a href="{{url('/fitment/show/'.$value->details_id)}}"><img src="{{asset(env('STATIC_FILE_ERP_PATH').$param['combine'][0]->fitment_details_imgMaster)}}" style="width: 100px;height: 100px;"></a></dt>
                                                    <dd>¥{{$value->details_fixprice}}</dd>
                                                    <?php $combine_sum+=$value->details_fixprice;array_push($combine_ids,$value->details_id);?>
                                                </dl>
                                                <img style="margin:40px 6px 0 6px;" class="D" src="{{asset('/img/adventure4%20(2).png')}}">
                                            </div>
                                            @endforeach
                                            <div class="img3">
                                                <p>已选<span style="color:#f29600;">{{count($param['combine'])}}</span>个配件 套餐价<span style="color:#b34848;">¥{{$combine_sum}}</span>
                                                </p>
                                                <button type="button" class="btn btn-warning" onclick="add_combinecar({{json_encode($combine_ids)}})">加入购物车</button>
                                            </div>
                                            @else
                                            {{'推荐组合加家具'}}
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--右边-->
                        <div class="right">
                            <input type="hidden" name="details_id" value="{{$param['current']->details_id}}">
                            <input type="hidden" name="rent_type" value="1">
                            <div class="col-xs-5">
                                <!--颜色选择-->
                                <div class="con1">
                                    <h3>{{$param['current']->fitments_name}}</h3>
                                    <p>{{$param['current']->fitments_describe}}</p>
                                    <div style="font-size: 18px; font-weight: normal;">
                                        颜色:@foreach($param['detail_colors'] as $key=>$value)
                                            <img src="{{$param['color'][$value->color_type]}}" alt="家具颜色">
                                            @endforeach
                                    </div>
                                </div>
                                <!--规格选择-->
                                <div class="con2">
                                    <p style="font-size: 18px;">选择:</p>
                                    @foreach($param['details'] as $v)
                                    <a href="{{url('/fitment/show/'.$v->details_id)}}">
                                    <label @if($v->details_id == $param['current_id'])class="active"@endif>
                                        <b @if($v->details_id == $param['current_id'])class="active"@endif></b>
                                        <span>{{$v->details_name}}{{$v->details_length}}*{{$v->details_width}}</span>
                                    </label>
                                    </a>
                                    @endforeach
                                </div>
                                <!--租期选择-->
                                <div class="con3">
                                    <p style="font-size: 18px;">租赁方式： </p>
                                    <div class="Ks">
                                        <div class="K1 active" onclick="fitment_dt_rent(1)">
                                            <label style="color: #ccc;">
                                                <b class="active"></b>&nbsp;&nbsp;&nbsp;
                                                随租随还
                                            </label>
                                            <p>租金：<span>¥{{$param['current']->details_nimbleprice}}</span></p>
                                            <p style="margin-bottom: 11px;">租期：<span>12个月</span></p>
                                        </div>
                                        <div class="K1" onclick="fitment_dt_rent(2)">
                                            <label style="color:#ccc;">
                                                <b></b>&nbsp;&nbsp;&nbsp;
                                                租满即送
                                            </label>
                                            <p>租金：<span>¥{{$param['current']->details_fixprice}}</span></p>
                                            <p style="margin-bottom: 11px;">租期：<span>18个月</span></p>
                                        </div>
                                    </div>
                                </div>
                                <!--数量/使用日期-->
                                <div class="con4">
                                    <div class="one">
                                        <p style="cursor:pointer">数量:</p>
                                        <div class="number">
                                            <b class="glyphicon glyphicon-minus-sign"></b>
                                            <span id="boom">1</span>
                                            <b class="glyphicon glyphicon-plus-sign"></b>
                                        </div>
                                    </div>
                                    <div class="two">
                                        <label style="font-weight: normal; font-size: 18px;">使用日期：</label>
                                        <input type="text" name="use_date" value="{{date('Y-m-d',strtotime('+3 days'))}}" id="date">
                                    </div>
                                    <div class="three">
                                        @if(session('user'))
                                        <button style="background-color:#f29600; " type="button" class="btn btn-warning" onclick="cartinsert()">
                                            加入购物车
                                        </button>
                                        <button style="background-color:#b34848; " type="button" class="btn btn-warning" onclick="immediatorder()">
                                            立即租赁
                                        </button>
                                        @else
                                        <button style="background-color:#f29600; " type="button" class="btn btn-warning" onclick="alert('请先登陆!');">
                                            加入购物车
                                        </button>
                                        <button style="background-color:#b34848; " type="button" class="btn btn-danger" onclick="alert('请先登陆!');">
                                            立即租赁
                                        </button>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 产品信息 下面 -->
                    <div id="bom">
                        <div>
                            <div class="panel-heading">
                                <h3 style="margin-top: 10px;">产品信息</h3>
                            </div>
                            <div class="panel-body">
                              <?php echo preg_replace('/ src="/', ' src="'.env('STATIC_FILE_ERP_PATH'),$param['details'][0]->fitments_contents);?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
